//
//  CHQueryTableViewController.m
//  CarFile
//
//  Created by 陈浩 on 2017/5/24.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHQueryTableViewController.h"
#import "CHWXJLDetailsViewController.h"
#import "CHRepairDetailController.h"
#import "QY_Model.h"
#import "CHWXJLCell.h"
#import "CHRepairCell.h"
@interface CHQueryTableViewController ()
@property (nonatomic ,strong) NSMutableArray *qydatas;
@end

@implementation CHQueryTableViewController
-(NSMutableArray *)datas{
    if (!_qydatas) {
        _qydatas = [NSMutableArray array];
    }
    return _qydatas;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    [self getData];
    
}


-(void)getData{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"areaid"] = [Util getValue:@"areaid"];
    params[@"usertype"] = [Util getValue:@"usertype"];
    params[@"user"] = [Globle getInstance].user;
    params[@"sign"] = [DESCript encrypt:(NSString *)[Util getValue:@"areaid"] encryptOrDecrypt:kCCEncrypt key:[Globle getInstance].key];
    params[@"pagesize"] = @"50";
    params[@"pagenum"] = @"1";
    
    [[Globle getInstance].service requestWithServiceName:@"lcipappgovcompanylist" params:params httpMethod:@"POST" resultIsDictionary:YES completeBlock:^(id result) {
        
        if ([result[@"code"] isEqualToString:@"1"]) {
            for (NSDictionary *dict in result[@"data"][@"list"]) {

                QY_Model *model = [QY_Model objectWithKeyValues:dict];
                [self.qydatas addObject:model];
            }
           
            [self.tableView reloadData];
        }
    }];

    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.qydatas.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.index ==1) {
        
        CHWXJLCell *cell = [CHWXJLCell cellForTableView:tableView];
        return cell;
    }else{
        CHRepairCell *cell = [CHRepairCell cellForTableView:tableView];
        cell.model = self.datas[indexPath.row];
        cell.scoreNum = 3;
        return cell;
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.index == 1) {
        return 120;
    }
    return 130;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.index == 1) {
        
        CHWXJLDetailsViewController *wxjlVC = [[CHWXJLDetailsViewController alloc] init];
        [self.navigationController pushViewController:wxjlVC animated:YES];
        
    }else{
        
        CHRepairDetailController *repairVc = [[CHRepairDetailController alloc] init];
        QY_Model *model = self.qydatas[indexPath.row];
        repairVc.companyid = model.companyid;
        [self.navigationController pushViewController:repairVc animated:YES];
    }
    
    
}

//
//补全分割线
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell  respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)])
    {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}


@end
